Mouse

splicing <- c("SE","MXE","RI","A3SS","A5SS")
all_psi <- c()
splice_type <- c()

mouse <- read.delim("~/Desktop/MISO_proj/EuropeanDataset/data/Sample_Metadata_Mouse_Heart-Brain-Only.tsv",sep="\t",header = T,stringsAsFactors = F)
mouse <- mouse[order(mouse$Source.Name),]

# Color bars for heatmaps
heart.samps <- mouse$Source.Name[which(mouse$Characteristics.organism.part.=="heart")]
brain.samps <- mouse$Source.Name[which(mouse$Characteristics.organism.part.!="heart")]

half <- floor(nrow(mouse)/2)

# Combine the matrices into one matrix
for (splice in splicing){
    x <- read.csv(paste("/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/EuropeanDataset/mouse/cohort_level/miso_counts_",splice,"_mat.csv",sep=""),header=T,row.names = 1,check.names = F)
    colnames(x) <- sub(".counts.txt","",colnames(x))
    x <- x[,order(colnames(x))]
    y <- apply(x,1,function(row){table(is.na(row))["FALSE"] >= half})
    x <- x[y==T,]
    splice_type <- c(splice_type,rep(splice,nrow(x)))
    all_psi <- rbind(all_psi,data.frame(x,SpliceType=splice))
    
}

Heart

heart <- data.frame(Samples = mouse$Source.Name[which(mouse$Characteristics.organism.part.=="heart")], DevelopStage = mouse$Characteristics.age.[which(mouse$Characteristics.organism.part.=="heart")])
heart$Group <- ""

heart$Group[which(heart$DevelopStage == 28.0 | heart$DevelopStage == 63.0)] <- "Adult"
heart$Group[which(heart$DevelopStage == 14.0)] <- "Adolescent"
heart$Group[which(heart$DevelopStage == 3.0 | heart$DevelopStage == 0.0)] <- "Postnatal"
heart$Group[which(heart$DevelopStage == 17.5 | heart$DevelopStage == 18.5)] <- "Very_Late_Embryo"
heart$Group[which(heart$DevelopStage == 15.5 | heart$DevelopStage == 16.5)] <- "Late_Embryo"
heart$Group[which(heart$DevelopStage == 13.5 | heart$DevelopStage == 14.5)] <- "Midstage_Embryo"
heart$Group[which(heart$DevelopStage == 12.5)] <- "Developing_Embryo"
heart$Group[which(heart$DevelopStage == 10.5 | heart$DevelopStage == 11.5)] <- "Early_Embryo"
colnames(all_psi) <- sub("^X","",colnames(all_psi))
heart.psi <- all_psi[,heart.samps]
heart.psi.complete <- heart.psi[complete.cases(heart.psi),]
heart.psi.complete <- heart.psi.complete[,order(colnames(heart.psi.complete))]
heart.psi.100 <- heart.psi.complete * 100 # turn psi values into integers
heart.psi.100 <- round(heart.psi.100,0)

# dim(heart.psi.100)
design <- model.matrix(~heart$Group)
y = DGEList(counts=heart.psi.100, group = heart$Group)
y <- estimateDisp(y,design)
fit <- glmQLFit(y, design)
fit <- glmQLFTest(fit, coef=2:7)
tab <- as.data.frame(topTags(fit, n=300))
# translate <- c()
# 
# for(splice in splicing){
#     tr <- as.data.frame(fread(paste("/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/data/mouse/", splice, ".mm10lnc.gff3.expanded_attr.csv",sep=""),header=T,stringsAsFactors = F))
#   tr$ID <- sub(" ","",tr$ID)
#   tr$GeneSymbol <- sub(" ","",tr$GeneSymbol)
#   tr <- tr[which(tr$type=="gene"),]
#   tr <- tr[,c("type","GeneSymbol","ID")]
#   
#   translate <- rbind(translate,tr)
# }
# head(translate)
# write.table(translate,file="/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/data/mouse/allSplice.mm10lnc.gff3.truncated.tsv",sep="\t",quote=F,row.names = F)

translate <- as.data.frame(fread("/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/data/mouse/allSplice.mm10lnc.gff3.truncated.tsv"))
tab$Gene <- sapply(rownames(tab),function(name){translate$GeneSymbol[which(translate$ID==name)]})

# write.table(tab,file="/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Heart_DEisoforms.tsv",sep="\t",col.names = NA)
# kable(head(tab)) %>% kable_styling()
top5 <- c("chr12:109544027:109544742:+@chr12:109544948:109545041:+@chr12:109546430:109546542:+",
          "chr7:81523550:81523676:+@chr7:81528787:81528940:+@chr7:81529347:81529527:+",
          "chr5:136925704:136925895:+@chr5:136928070:136928280:+@chr5:136933739:136937112:+",
          "chr12:109651859:109651938:+@chr12:109652701:109652715:+@chr12:109654286:109654432:+",
          "chr17:12741311:12741424:+@chr17:12798359:12798439:+@chr17:12829825:12830336:+")
    
top5 <- as.data.frame(heart.psi.complete[top5,])
top5 <- merge(top5,translate,by.x=0,by.y=3, all.x = T, all.y=F)
heart$Group <- factor(heart$Group, levels=c("Early_Embryo",
                                           "Developing_Embryo",
                                           "Midstage_Embryo",
                                           "Late_Embryo",
                                           "Very_Late_Embryo",
                                           "Postnatal",
                                           "Adolescent",
                                           "Adult"))

top5.melt <- reshape2::melt(top5)
top5.melt <- merge(top5.melt,heart,by.x=4,by.y = 1)

Top 5 Most Significantly DE Isoforms

ggplot(top5.melt,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") + 
    facet_wrap(~Row.names) + theme_bw() + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5), 
          strip.text.x = element_text(color="black",face = "bold",size=7))

new <- heart.psi.complete[rownames(tab)[which(tab$FDR<0.05)],]

rownames(new) <- sapply(rownames(new),function(name){paste(translate$GeneSymbol[which(translate$ID==name)],name,sep="_")})


new$transcripts <- rownames(new)
new.melt <- melt(new)
new.melt <- merge(new.melt,heart,by.x=2,by.y=1)

# head(new.melt)
transcripts <- unique(new.melt$transcripts)

pdf("/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Heart_DEisoforms_Boxplots.pdf",width = 9,height = 7)
for (trans in transcripts){
  df <- new.melt[which(new.melt$transcripts==trans),]
  
  print(ggplot(df,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") +  theme_bw() + 
    ggtitle(paste(str_wrap(trans, width = 75))) + xlab("") + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5),
          plot.title = element_text(hjust=0.5,size = 12), legend.position = "none") )
}

dev.off()
## quartz_off_screen 
##                 2
heart <- heart[order(heart$Group),]

ra <- HeatmapAnnotation(Group = heart$Group,col = list(Group=c("Postnatal"= "purple",
                                                               "Adult" = "coral3", 
                                                               "Midstage_Embryo"="blue",
                                                               "Early_Embryo" = "yellow",
                                                               "Late_Embryo" = "brown", 
                                                               "Very_Late_Embryo"="black",
                                                               "Adolescent"= "cyan3",
                                                               "Developing_Embryo"="deeppink1")))

#ha <- HeatmapAnnotation(SpliceType = splice_type, col=list(SpliceType=c("SE"="red","MXE"="blue","RI"="cyan3","A3SS"="yellow","A5SS"="orange")))

lt05 <- rownames(tab)[which(tab$FDR < 0.05)]

toplot <- heart.psi.complete[lt05,]
toplot <- medianCtr(toplot)


draw(Heatmap(as.matrix(toplot), cluster_columns = F, name = "PSI",column_title = "Top DE Transcripts (FDR < 0.05)\nMouse Heart Samples", clustering_distance_columns = "pearson",clustering_method_columns = "average", bottom_annotation = ra, row_names_max_width = max_text_width(rownames(toplot), gp = gpar(fontsize = 3))),heatmap_legend_side = "left", annotation_legend_side = "left")

kable(table(heart$DevelopStage,heart$Group)) %>% kable_styling()
Early_Embryo Developing_Embryo Midstage_Embryo Late_Embryo Very_Late_Embryo Postnatal Adolescent Adult
0 0 0 0 0 0 4 0 0
3 0 0 0 0 0 4 0 0
10.5 4 0 0 0 0 0 0 0
11.5 4 0 0 0 0 0 0 0
12.5 0 4 0 0 0 0 0 0
13.5 0 0 4 0 0 0 0 0
14 0 0 0 0 0 0 4 0
14.5 0 0 3 0 0 0 0 0
15.5 0 0 0 4 0 0 0 0
16.5 0 0 0 4 0 0 0 0
17.5 0 0 0 0 4 0 0 0
18.5 0 0 0 0 4 0 0 0
28 0 0 0 0 0 0 0 4
63 0 0 0 0 0 0 0 4

Mouse Brain

Forebrain

# splicing <- c("SE","MXE","RI","A3SS","A5SS")

# splice_type <- c()

# mouse <- read.delim("~/Desktop/MISO_proj/EuropeanDataset/data/Sample_Metadata_Mouse_Heart-Brain-Only.tsv",sep="\t",header = T,stringsAsFactors = F)
# mouse <- mouse[order(mouse$Source.Name),]


fore.samps <- mouse$Source.Name[which(mouse$Characteristics.organism.part.=="forebrain")]



# Combine the matrices into one matrix
# for (splice in splicing){
#     x <- read.csv(paste("/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/EuropeanDataset/mouse/cohort_level/miso_counts_",splice,"_mat.csv",sep=""),header=T,row.names = 1,check.names = F)
#     colnames(x) <- sub(".counts.txt","",colnames(x))
#     x <- x[,order(colnames(x))]
#     y <- apply(x,1,function(row){table(is.na(row))["FALSE"] >= half})
#     x <- x[y==T,]
#     splice_type <- c(splice_type,rep(splice,nrow(x)))
#     all_psi <- rbind(all_psi,data.frame(x,SpliceType=splice))
#     
# }
fbrain <- data.frame(Samples = mouse$Source.Name[which(mouse$Characteristics.organism.part.=="forebrain")], DevelopStage = mouse$Characteristics.age.[which(mouse$Characteristics.organism.part.=="forebrain")])
fbrain$Group <- ""

fbrain$Group[which(fbrain$DevelopStage == 28.0 | fbrain$DevelopStage == 63.0)] <- "Adult"
fbrain$Group[which(fbrain$DevelopStage == 14.0)] <- "Adolescent"
fbrain$Group[which(fbrain$DevelopStage == 3.0 | fbrain$DevelopStage == 0.0)] <- "Postnatal"
fbrain$Group[which(fbrain$DevelopStage == 17.5 | fbrain$DevelopStage == 18.5)] <- "Very_Late_Embryo"
fbrain$Group[which(fbrain$DevelopStage == 15.5 | fbrain$DevelopStage == 16.5)] <- "Late_Embryo"
fbrain$Group[which(fbrain$DevelopStage == 13.5 | fbrain$DevelopStage == 14.5)] <- "Midstage_Embryo"
fbrain.psi <- all_psi[,fore.samps]
fbrain.psi.complete <- fbrain.psi[complete.cases(fbrain.psi),]
fbrain.psi.complete <- fbrain.psi.complete[,order(colnames(fbrain.psi.complete))]
fbrain.psi.100 <- fbrain.psi.complete * 100 # turn psi values into integers
fbrain.psi.100 <- round(fbrain.psi.100,0)
design <- model.matrix(~fbrain$Group)
y = DGEList(counts=fbrain.psi.100, group = fbrain$Group)
y <- estimateDisp(y,design)
fit <- glmQLFit(y, design)
fit <- glmQLFTest(fit, coef=2:6)
tab <- as.data.frame(topTags(fit, n=450))

tab$Gene <- sapply(rownames(tab),function(name){translate$GeneSymbol[which(translate$ID==name)]})

# write.table(tab, file = "/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Forebrain_DEisoforms.tsv",sep="\t",col.names = NA)
# kable(head(tab)) %>% kable_styling()
# translate <- as.data.frame(fread("/Users/alisha/Desktop/faster_Datastore/Alisha/MISO_project/data/mouse/allSplice.mm10lnc.gff3.truncated.tsv"))
top5 <- c("chr9:41579978:41580198:+@chr9:41580713:41581402:+@chr9:41590220:41592829:+",
          "chr12:109637839:109637926:+@chr12:109640267:109640328:+@chr12:109642565:109642652:+",
          "chr9:41528123:41528200:+@chr9:41576408:41576549:+@chr9:41589974:41590167:+",
          "chr14:55056024:55056177|55056430:+@chr14:55097380:55098986:+",
          "chr12:109637839:109637926:+@chr12:109640267:109640328:+@chr12:109642565:109642652:+@chr12:109643414:109643461:+")
    
top5 <- as.data.frame(fbrain.psi.complete[top5,])
top5 <- merge(top5,translate,by.x=0,by.y=3, all.x = T, all.y=F)
fbrain$Group <- factor(fbrain$Group, levels=c("Midstage_Embryo",
                                           "Late_Embryo",
                                           "Very_Late_Embryo",
                                           "Postnatal",
                                           "Adolescent",
                                           "Adult"))

top5.melt <- reshape2::melt(top5)
top5.melt <- merge(top5.melt,fbrain,by.x=4,by.y = 1)

Top 5 Most Significantly DE Isoforms

ggplot(top5.melt,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") + 
    facet_wrap(~Row.names) + theme_bw() + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5), 
          strip.text.x = element_text(color="black",face = "bold",size=7))

new <- fbrain.psi.complete[rownames(tab)[which(tab$FDR<0.05)],]

rownames(new) <- sapply(rownames(new),function(name){paste(translate$GeneSymbol[which(translate$ID==name)],name,sep="_")})


new$transcripts <- rownames(new)
new.melt <- melt(new)
new.melt <- merge(new.melt,fbrain,by.x=2,by.y=1)

# head(new.melt)
transcripts <- unique(new.melt$transcripts)

pdf("/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Forebrain_DEisoforms_Boxplots.pdf",width = 9,height = 7)
for (trans in transcripts){
  df <- new.melt[which(new.melt$transcripts==trans),]
  
  print(ggplot(df,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") +  theme_bw() + 
    ggtitle(paste(str_wrap(trans, width = 75))) + xlab("") + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5),
          plot.title = element_text(hjust=0.5,size = 12), legend.position = "none") )
}

dev.off()
## quartz_off_screen 
##                 2
fbrain <- fbrain[order(fbrain$Group),]

ra <- HeatmapAnnotation(Group = fbrain$Group,col = list(Group=c("Postnatal"= "purple",
                                                               "Adult" = "coral3", 
                                                               "Midstage_Embryo"="blue",
                                                               # "Early_Embryo" = "yellow",
                                                               "Late_Embryo" = "brown",
                                                               "Very_Late_Embryo"="black",
                                                               "Adolescent"= "cyan3")))
                                                               # "Developing_Embryo"="deeppink1")))

#ha <- HeatmapAnnotation(SpliceType = splice_type, col=list(SpliceType=c("SE"="red","MXE"="blue","RI"="cyan3","A3SS"="yellow","A5SS"="orange")))

lt05 <- rownames(tab)[which(tab$FDR < 0.05)]

toplot <- fbrain.psi.complete[lt05,]
toplot <- medianCtr(toplot) #log2(toplot+1))


draw(Heatmap(as.matrix(toplot), cluster_columns = F, name = "PSI",column_title = "Top DE Transcripts (FDR < 0.05)\nMouse Forebrain Samples", clustering_distance_columns = "pearson",clustering_method_columns = "average", bottom_annotation = ra, row_names_max_width = max_text_width(rownames(toplot), gp = gpar(fontsize = 3))),heatmap_legend_side = "left", annotation_legend_side = "left")

kable(fbrain) %>% kable_styling()
Samples DevelopStage Group
28 2223sTS.Mouse.Brain.14.5.Male 14.5 Midstage_Embryo
29 2227sTS.Mouse.Brain.14.5.Female 14.5 Midstage_Embryo
30 2237sTS.Mouse.Brain.14.5.Male 14.5 Midstage_Embryo
31 2243sTS.Mouse.Brain.14.5.Female 14.5 Midstage_Embryo
41 2813sTS.Mouse.Brain.13.5.Female 13.5 Midstage_Embryo
42 2821sTS.Mouse.Brain.13.5.Male 13.5 Midstage_Embryo
43 2829sTS.Mouse.Brain.13.5.Female 13.5 Midstage_Embryo
44 2837sTS.Mouse.Brain.13.5.Male 13.5 Midstage_Embryo
25 2185sTS.Mouse.Brain.15.5.Male 15.5 Late_Embryo
26 2189sTS.Mouse.Brain.15.5.Female 15.5 Late_Embryo
27 2193sTS.Mouse.Brain.15.5.Male 15.5 Late_Embryo
32 2247sTS.Mouse.Brain.15.5.Female 15.5 Late_Embryo
33 2254sTS.Mouse.Brain.16.5.Female 16.5 Late_Embryo
34 2257sTS.Mouse.Brain.16.5.Male 16.5 Late_Embryo
35 2273sTS.Mouse.Brain.16.5.Female 16.5 Late_Embryo
36 2276sTS.Mouse.Brain.16.5.Male 16.5 Late_Embryo
21 2157sTS.Mouse.Brain.17.5.Male 17.5 Very_Late_Embryo
22 2160sTS.Mouse.Brain.17.5.Male 17.5 Very_Late_Embryo
23 2163sTS.Mouse.Brain.17.5.Female 17.5 Very_Late_Embryo
24 2165sTS.Mouse.Brain.17.5.Female 17.5 Very_Late_Embryo
37 2307sTS.Mouse.Brain.18.5.Male 18.5 Very_Late_Embryo
38 2313sTS.Mouse.Brain.18.5.Female 18.5 Very_Late_Embryo
39 2317sTS.Mouse.Brain.18.5.Male 18.5 Very_Late_Embryo
40 2323sTS.Mouse.Brain.18.5.Female 18.5 Very_Late_Embryo
1 1740sTS.Mouse.Brain.0dpb.Female 0.0 Postnatal
8 1900sTS.Mouse.Brain.0dpb.Female 0.0 Postnatal
9 1906sTS.Mouse.Brain.0dpb.Male 0.0 Postnatal
10 1912sTS.Mouse.Brain.0dpb.Male 0.0 Postnatal
11 1918sTS.Mouse.Brain.3dpb.Female 3.0 Postnatal
12 1924sTS.Mouse.Brain.3dpb.Male 3.0 Postnatal
13 1930sTS.Mouse.Brain.3dpb.Female 3.0 Postnatal
20 1964sTS.Mouse.Brain.3dpb.Male 3.0 Postnatal
2 1876sTS.Mouse.Brain.2wpb.Male 14.0 Adolescent
3 1880sTS.Mouse.Brain.2wpb.Male 14.0 Adolescent
4 1884sTS.Mouse.Brain.2wpb.Female 14.0 Adolescent
5 1888sTS.Mouse.Brain.2wpb.Female 14.0 Adolescent
6 1892sTS.Mouse.Brain.4wpb.Male 28.0 Adult
7 1896sTS.Mouse.Brain.4wpb.Male 28.0 Adult
14 1936sTS.Mouse.Brain.4wpb.Female 28.0 Adult
15 1940sTS.Mouse.Brain.4wpb.Female 28.0 Adult
16 1944sTS.Mouse.Brain.9wpb.Male 63.0 Adult
17 1948sTS.Mouse.Brain.9wpb.Female 63.0 Adult
18 1954sTS.Mouse.Brain.9wpb.Male 63.0 Adult
19 1960sTS.Mouse.Brain.9wpb.Female 63.0 Adult

Hindbrain

splicing <- c("SE","MXE","RI","A3SS","A5SS")



hind.samps <- mouse$Source.Name[which(mouse$Characteristics.organism.part.=="hindbrain")]
hbrain <- data.frame(Samples = mouse$Source.Name[which(mouse$Characteristics.organism.part.=="hindbrain")], DevelopStage = mouse$Characteristics.age.[which(mouse$Characteristics.organism.part.=="hindbrain")])
hbrain$Group <- ""

hbrain$Group[which(hbrain$DevelopStage == 28.0 | hbrain$DevelopStage == 63.0)] <- "Adult"
hbrain$Group[which(hbrain$DevelopStage == 14.0)] <- "Adolescent"
hbrain$Group[which(hbrain$DevelopStage == 3.0 | hbrain$DevelopStage == 0.0)] <- "Postnatal"
hbrain$Group[which(hbrain$DevelopStage == 17.5 | hbrain$DevelopStage == 18.5)] <- "Very_Late_Embryo"
hbrain$Group[which(hbrain$DevelopStage == 15.5 | hbrain$DevelopStage == 16.5)] <- "Late_Embryo"
hbrain$Group[which(hbrain$DevelopStage == 13.5 | hbrain$DevelopStage == 14.5)] <- "Midstage_Embryo"
# colnames(all_psi) <- sub("^X","",colnames(all_psi))
hbrain.psi <- all_psi[,hind.samps]
hbrain.psi.complete <- hbrain.psi[complete.cases(hbrain.psi),]
hbrain.psi.complete <- hbrain.psi.complete[,order(colnames(hbrain.psi.complete))]
hbrain.psi.100 <- hbrain.psi.complete * 100 # turn psi values into integers
hbrain.psi.100 <- round(hbrain.psi.100,0)
design <- model.matrix(~hbrain$Group)
y = DGEList(counts=hbrain.psi.100, group = hbrain$Group)
y <- estimateDisp(y,design)
fit <- glmQLFit(y, design)
fit <- glmQLFTest(fit, coef=2:6)
tab <- as.data.frame(topTags(fit, n=500))

tab$Gene <- sapply(rownames(tab),function(name){translate$GeneSymbol[which(translate$ID==name)]})

write.table(tab, file = "/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Hindbrain_DEisoforms.tsv",sep="\t",col.names = NA)
# kable(head(tab)) %>% kable_styling()
top5 <- c("chr8:87524296-87524427:+@chr8:87525415-87525552:+",
          "chr12:109627048:109627153:+@chr12:109634194:109634354:+@chr12:109635394:109635457:+",
          "chr9:41579978:41580198:+@chr9:41580713:41581402:+@chr9:41590220:41592829:+",
          "chr12:109742062:109742290:+@chr12:109743357:109743418:+@chr12:109743666:109743847:+",
          "chr12:109637839:109637926:+@chr12:109640267:109640328:+@chr12:109642565:109642652:+")
    
top5 <- as.data.frame(hbrain.psi.complete[top5,])
top5 <- merge(top5,translate,by.x=0,by.y=3, all.x = T, all.y=F)
hbrain$Group <- factor(hbrain$Group, levels=c("Midstage_Embryo",
                                           "Late_Embryo",
                                           "Very_Late_Embryo",
                                           "Postnatal",
                                           "Adolescent",
                                           "Adult"))

top5.melt <- reshape2::melt(top5)
top5.melt <- merge(top5.melt,hbrain,by.x=4,by.y = 1)

Top 5 Most Significantly DE Isoforms

ggplot(top5.melt,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") + 
    facet_wrap(~Row.names) + theme_bw() + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5), 
          strip.text.x = element_text(color="black",face = "bold",size=7))

new <- hbrain.psi.complete[rownames(tab)[which(tab$FDR<0.05)],]

rownames(new) <- sapply(rownames(new),function(name){paste(translate$GeneSymbol[which(translate$ID==name)],name,sep="_")})


new$transcripts <- rownames(new)
new.melt <- melt(new)
new.melt <- merge(new.melt,hbrain,by.x=2,by.y=1)

# head(new.melt)
transcripts <- unique(new.melt$transcripts)

pdf("/Users/alisha/Desktop/MISO_proj/EuropeanDataset/Mouse_Hindbrain_DEisoforms_Boxplots.pdf",width = 9,height = 7)
for (trans in transcripts){
  df <- new.melt[which(new.melt$transcripts==trans),]
  
  print(ggplot(df,aes(x=Group, y=value,fill=Group)) + geom_boxplot() + ylab("PSI") +  theme_bw() + 
    ggtitle(paste(str_wrap(trans, width = 75))) + xlab("") + 
    theme(axis.text.x = element_text(color = "black",size = 14, angle = 90, hjust = 1,vjust = 0.5),
          plot.title = element_text(hjust=0.5,size = 12), legend.position = "none") )
}

dev.off()
## quartz_off_screen 
##                 2
hbrain <- hbrain[order(hbrain$Group),]

ra <- HeatmapAnnotation(Group = hbrain$Group,col = list(Group=c("Postnatal"= "purple",
                                                               "Adult" = "coral3", 
                                                               "Midstage_Embryo"="blue",
                                                               # "Early_Embryo" = "yellow",
                                                               "Late_Embryo" = "brown",
                                                               "Very_Late_Embryo"="black",
                                                               "Adolescent"= "cyan3")))
                                                               # "Developing_Embryo"="deeppink1")))

#ha <- HeatmapAnnotation(SpliceType = splice_type, col=list(SpliceType=c("SE"="red","MXE"="blue","RI"="cyan3","A3SS"="yellow","A5SS"="orange")))

lt05 <- rownames(tab)[which(tab$FDR < 0.05)]

toplot <- hbrain.psi.complete[lt05,]
toplot <- medianCtr(toplot) #log2(toplot+1))


draw(Heatmap(as.matrix(toplot), cluster_columns = F, name = "PSI",column_title = "Top DE Transcripts (FDR < 0.05)\nMouse Hindbrain Samples", clustering_distance_columns = "pearson",clustering_method_columns = "average", bottom_annotation = ra, row_names_max_width = max_text_width(rownames(toplot), gp = gpar(fontsize = 3))),heatmap_legend_side = "left", annotation_legend_side = "left")

kable(hbrain) %>% kable_styling()
Samples DevelopStage Group
27 2224sTS.Mouse.Cerebellum.14.5.Male 14.5 Midstage_Embryo
28 2228sTS.Mouse.Cerebellum.14.5.Female 14.5 Midstage_Embryo
29 2238sTS.Mouse.Cerebellum.14.5.Male 14.5 Midstage_Embryo
30 2244sTS.Mouse.Cerebellum.14.5.Female 14.5 Midstage_Embryo
39 2814sTS.Mouse.Cerebellum.13.5.Female 13.5 Midstage_Embryo
40 2822sTS.Mouse.Cerebellum.13.5.Male 13.5 Midstage_Embryo
41 2830sTS.Mouse.Cerebellum.13.5.Female 13.5 Midstage_Embryo
42 2838sTS.Mouse.Cerebellum.13.5.Male 13.5 Midstage_Embryo
23 2186sTS.Mouse.Cerebellum.15.5.Male 15.5 Late_Embryo
24 2190sTS.Mouse.Cerebellum.15.5.Female 15.5 Late_Embryo
25 2194sTS.Mouse.Cerebellum.15.5.Male 15.5 Late_Embryo
26 2218sTS.Mouse.Cerebellum.15.5.Female 15.5 Late_Embryo
31 2255sTS.Mouse.Cerebellum.16.5.Female 16.5 Late_Embryo
32 2258sTS.Mouse.Cerebellum.16.5.Male 16.5 Late_Embryo
33 2274sTS.Mouse.Cerebellum.16.5.Female 16.5 Late_Embryo
34 2277sTS.Mouse.Cerebellum.16.5.Male 16.5 Late_Embryo
19 2158sTS.Mouse.Cerebellum.17.5.Male 17.5 Very_Late_Embryo
20 2161sTS.Mouse.Cerebellum.17.5.Male 17.5 Very_Late_Embryo
21 2164sTS.Mouse.Cerebellum.17.5.Female 17.5 Very_Late_Embryo
22 2166sTS.Mouse.Cerebellum.17.5.Female 17.5 Very_Late_Embryo
35 2308sTS.Mouse.Cerebellum.18.5.Male 18.5 Very_Late_Embryo
36 2314sTS.Mouse.Cerebellum.18.5.Female 18.5 Very_Late_Embryo
37 2318sTS.Mouse.Cerebellum.18.5.Male 18.5 Very_Late_Embryo
38 2324sTS.Mouse.Cerebellum.18.5.Female 18.5 Very_Late_Embryo
1 1741sTS.Mouse.Cerebellum.0dpb.Female 0.0 Postnatal
7 1901sTS.Mouse.Cerebellum.0dpb.Female 0.0 Postnatal
8 1907sTS.Mouse.Cerebellum.0dpb.Male 0.0 Postnatal
9 1919sTS.Mouse.Cerebellum.3dpb.Female 3.0 Postnatal
10 1925sTS.Mouse.Cerebellum.3dpb.Male 3.0 Postnatal
11 1931sTS.Mouse.Cerebellum.3dpb.Female 3.0 Postnatal
18 1965sTS.Mouse.Cerebellum.3dpb.Male 3.0 Postnatal
43 3919sTS.Mouse.Cerebellum.0dpb.Male 0.0 Postnatal
2 1877sTS.Mouse.Cerebellum.2wpb.Male 14.0 Adolescent
3 1881sTS.Mouse.Cerebellum.2wpb.Male 14.0 Adolescent
4 1885sTS.Mouse.Cerebellum.2wpb.Female 14.0 Adolescent
5 1893sTS.Mouse.Cerebellum.4wpb.Male 28.0 Adult
6 1897sTS.Mouse.Cerebellum.4wpb.Male 28.0 Adult
12 1937sTS.Mouse.Cerebellum.4wpb.Female 28.0 Adult
13 1941sTS.Mouse.Cerebellum.4wpb.Female 28.0 Adult
14 1945sTS.Mouse.Cerebellum.9wpb.Male 63.0 Adult
15 1949sTS.Mouse.Cerebellum.9wpb.Female 63.0 Adult
16 1955sTS.Mouse.Cerebellum.9wpb.Male 63.0 Adult
17 1961sTS.Mouse.Cerebellum.9wpb.Female 63.0 Adult